//
//  BN_MyInfoHelper.m
//  BabyNow
//
//  Created by 闫建刚 on 14-5-26.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import "BN_MyInfoHelper.h"
#import "BN_UserInfo.h"
#import "BN_UserHelper.h"
#import "IMB_NetWorkJsonRespOperation.h"
#import "IMB_NetWorkAccessOperationWithFilesUpload.h"

@interface BN_MyInfoHelper(){
    
    // 周评列表当前页码
    int pageNoForEval_;
    
    
    // add by jason yan 2014-06-05
    // 家长首页当前页码
    int pageNoForParentHome_;
    
    // 家长首页信息数组
    NSMutableArray *parentHomeInfoArr_;
    
    // 周评列表数据
    NSMutableArray *evalArr_;
    
    // add by jason yan 2014-06-19
    
    // 文件上传任务
    IMB_NetWorkAccessOperationWithFilesUpload *uploadOperation_;
    
    // 上传进度回调处理
    UploadProcessingHandler uploadProcessingHandler_;
    
}

/**
 *  查询家长首页信息队列
 */
@property (nonatomic,strong) NSOperationQueue *queryParentHomeInfoQueue;

/**
 *  查询老师首页信息队列
 */
@property (nonatomic,strong) NSOperationQueue *queryTeacherHomeInfoQueue;

/**
 *  查询周评列表队列
 */
@property (nonatomic,strong) NSOperationQueue *queryEvalListQueue;

/**
 *  用户信息更新队列
 */
@property (nonatomic,strong) NSOperationQueue *updateUserInfoQueue;

/**
 *  查询指定页码的周评列表
 *
 *  @param pageno   页码
 *  @param childId  宝宝编号
 */
- (void)queryEvalListForPageNo:(int)pageno
                       childId:(NSString*)childId;

// add by jason yan 2014-06-05
/**
 *  查询指定页码的家长首页信息
 *
 *  @param pageNo 指定页码
 */
- (void)queryParentHomeInfoForPageNo:(int)pageNo;

@end

@implementation BN_MyInfoHelper

#pragma mark - Extend method
// 查询指定页码的家长首页信息
- (void)queryParentHomeInfoForPageNo:(int)pageNo{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_PARENT_HOME_INFO requestMethod:NET_REQUEST_GET paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password,kPageNo:[NSString stringWithFormat:@"%d",pageNo]} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                NSDictionary *info = result[kinfo];
                
                if (pageNo == 1) {
                    [parentHomeInfoArr_ removeAllObjects];
                }
                
                NSMutableDictionary *childInfoDict;
                // 设置宝宝信息
                if (parentHomeInfoArr_.count > 0) {
                    childInfoDict = parentHomeInfoArr_[0];
                }else{
                    childInfoDict = [NSMutableDictionary dictionary];
                    [parentHomeInfoArr_ addObject:childInfoDict];
                }
                childInfoDict[kChilId] = info[kChilId];
                childInfoDict[kMedaCoun] = info[kMedaCoun];
                childInfoDict[kEvalCoun] = info[kEvalCoun];
                
                NSArray *favoInfoArr = info[kFavoInfo];
                if ([favoInfoArr isKindOfClass:[NSArray class]] && favoInfoArr.count > 0) {
                    pageNoForParentHome_ = pageNo;
                    [parentHomeInfoArr_ addObjectsFromArray:favoInfoArr];
                    self.queryParentHomeListCompleteHandler(parentHomeInfoArr_,nil);
                }else{
                    if (pageNo == 1) {
                        self.queryParentHomeListCompleteHandler(parentHomeInfoArr_,NET_ERROR_MSG_FOR_NO_DATA);
                    }else{
                        self.queryParentHomeListCompleteHandler(parentHomeInfoArr_,NET_ERROR_MSG_FOR_NO_MORE_DATA);
                    }
                }
            }else{
                self.queryParentHomeListCompleteHandler(nil,result[kErrorMessage]);
            }
        }else{
            self.queryParentHomeListCompleteHandler(nil,errorMessage);
        }
    }];
    [self.queryParentHomeInfoQueue addOperation:operation];
}

#pragma mark - Interface method

// 刷新获取第一页家长首页信息
- (void)refreshParentHomeInfoList{
    
    if (self.queryParentHomeInfoQueue.operationCount > 0) {
        return;
    }
    
    [self queryParentHomeInfoForPageNo:1];
}

// 查询下一页家长首页信息
- (void)queryNextPageParentHomeInfoList{
    
    if (self.queryParentHomeInfoQueue.operationCount > 0) {
        return;
    }
    
    [self queryParentHomeInfoForPageNo:pageNoForParentHome_ + 1];
}


// 查询家长首页信息
- (void)queryParentHomeInfo:(DataHandleComplete)completeHandler{
    
    if (self.queryParentHomeInfoQueue.operationCount > 0) {
        //completeHandler(nil,nil);
        return;
    }
    
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_PARENT_HOME_INFO requestMethod:NET_REQUEST_GET paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [self.queryParentHomeInfoQueue addOperation:operation];
}


// 获取勋章详情
- (void)queryMedalList:(DataHandleComplete)completeHandler{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_MEDAL_DETAIL requestMethod:NET_REQUEST_GET paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
}

// 获取班级宝宝列表
- (void)queryChildList:(DataHandleComplete)completeHandler{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_CHILD_LIST requestMethod:NET_REQUEST_GET paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
}

// 获取勋章类型列表
- (void)queryMedalTypeListForChildId:(NSString *)childId
                     completeHandler:(DataHandleComplete)completeHandler{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_MEDAL_TYPE_LIST requestMethod:NET_REQUEST_GET paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password,kChilId:childId} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
}

// 颁发勋章
- (void)sendMedalInfoForChildId:(NSString *)childId
                        medalId:(NSString *)medalId
                completeHandler:(DataHandleComplete)completeHandler{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_SEND_MEDAL requestMethod:NET_REQUEST_POST paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password,kChilId:childId,kMedaId:medalId} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
}


// 刷新周评
- (void)refreshEvalList:(NSString*)childId{
    if (!_queryEvalListCompleteHandler) {
        NSAssert(_queryEvalListCompleteHandler, @"没有初始化周评列表回调处理");
        return;
    }
    if (self.queryEvalListQueue.operationCount > 0) {
        self.queryEvalListCompleteHandler(nil,nil);
        return;
    }
    [self queryEvalListForPageNo:1 childId:childId];
}


// 查询下一页周评列表
- (void)queryNextPageEvalList:(NSString *)childId{
    if (!_queryEvalListCompleteHandler) {
        NSAssert(_queryEvalListCompleteHandler, @"没有初始化周评列表回调处理");
        return;
    }
    if (self.queryEvalListQueue.operationCount > 0) {
        self.queryEvalListCompleteHandler(nil,nil);
        return;
    }
    [self queryEvalListForPageNo:pageNoForEval_ + 1 childId:childId];
}

// 取消查询周评列表
- (void)cancleQueryEvalList{
    [self.queryEvalListQueue.operations makeObjectsPerformSelector:@selector(cancelNetAccess)];
}


// 查询指定页码的周评列表
- (void)queryEvalListForPageNo:(int)pageno
                       childId:(NSString *)childId{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_EVAL_LIST requestMethod:NET_REQUEST_GET paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password,kChilId:childId} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                NSArray *arr = result[kinfo];
                if (arr.count > 0) {
                    pageNoForEval_ = pageno;
                    if (pageNoForEval_ == 1) {
                        [evalArr_ removeAllObjects];
                    }
                    [evalArr_ addObjectsFromArray:arr];
                    self.queryEvalListCompleteHandler(evalArr_,errorMessage);
                }else{
                    if (pageno == 1) {
                        self.queryEvalListCompleteHandler(nil,NET_ERROR_MSG_FOR_NO_DATA);
                    }else{
                        self.queryEvalListCompleteHandler(nil,NET_ERROR_MSG_FOR_NO_MORE_DATA);
                    }
                }
            }else{
                self.queryEvalListCompleteHandler(nil,result[kErrorMessage]);
            }
        }else{
            self.queryEvalListCompleteHandler(nil,errorMessage);
        }
    }];
    [self.queryEvalListQueue addOperation:operation];
}

// 发布周评
- (void)sendEvaLInfoForChildId:(NSString *)childId
                      evalCont:(NSString *)evalCont
               completeHandler:(DataHandleComplete)completeHandler{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_EVAL_SEND requestMethod:NET_REQUEST_POST paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password,kChilId:childId,kEvalCont:evalCont} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
}

// 获取老师首页信息
- (void)queryTeacherHomeInfo:(DataHandleComplete)completeHandler{
    if (self.queryTeacherHomeInfoQueue.operationCount > 0) {
        completeHandler(nil,nil);
        return;
    }
    
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_TEACHER_HOME_INFO requestMethod:NET_REQUEST_GET paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [self.queryTeacherHomeInfoQueue addOperation:operation];
}

// 获取积分列表
- (void)queryPrizList:(DataHandleComplete)completeHandler{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_PRIZ_LIST requestMethod:NET_REQUEST_GET paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
}

// 积分兑换
- (void)prizChangeWithPrizId:(NSString *)prizId pointNum:(NSString *)pointNum completeHandler:(DataHandleComplete)completeHandler{
    
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_POIN_EXCH requestMethod:NET_REQUEST_GET paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password,kPrizId:prizId,kPoinNumb:pointNum} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
    
}

// 积分规则
- (void)queryPointRule:(DataHandleComplete)completeHandler{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_POIN_RULE requestMethod:NET_REQUEST_GET paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
}

// 查询个人资料
- (void)queryUserInfo:(DataHandleComplete)completeHandler{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_USER_INFO requestMethod:NET_REQUEST_GET paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
}

// 更新个人资料信息
- (void)updateUserInfoWithBirthDate:(NSString *)birthDate
                           gradUniv:(NSString *)gradUniv
                               educ:(NSString *)educ
                               sign:(NSString *)sign
                              phone:(NSString *)phone
                     completeHandle:(DataHandleComplete)completeHandler{
 
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_UPDATA_USER_INFO requestMethod:NET_REQUEST_POST paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password,kBirtDate:(birthDate == nil ? @"" : birthDate),kGradUniv : gradUniv == nil ? @"" : gradUniv,kEduc : educ == nil ? @"" : educ, kSign : sign == nil ? @"" : sign, kPhon : phone == nil ? @"" : phone} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
    
}

// 更新个人资料(包含个人头像)
- (void)updateUserInfoWithBirthDate:(NSString *)birthDate
                           gradUniv:(NSString *)gradUniv
                               educ:(NSString *)educ
                               sign:(NSString *)sign
                              phone:(NSString *)phone
                       filesInfoArr:(NSArray *)fileInfoArr
                     completeHandle:(DataHandleComplete)completeHandler
            uploadProcessingHandler:(UploadProcessingHandler)uploadProcessHandler{
    
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    
    NSDictionary *params = nil;
    if (!fileInfoArr) {
        params = @{kAccount:userInfo.account,kPassword:userInfo.password,kBirtDate:(birthDate == nil ? @"" : birthDate),kGradUniv : gradUniv == nil ? @"" : gradUniv,kEduc : educ == nil ? @"" : educ, kSign : sign == nil ? @"" : sign, kPhon : phone == nil ? @"" : phone};
    }
    
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_UPDATA_USER_INFO requestMethod:NET_REQUEST_POST paramsValues:params completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    
    if (fileInfoArr.count > 0) {
        
        uploadProcessingHandler_ = uploadProcessHandler;
        
        // 1. 执行文件上传操作
        uploadOperation_ = [[IMB_NetWorkAccessOperationWithFilesUpload alloc]initWithUploadUrlStr:NET_IF_DYNAMIC_PUBLISH_UPLOAD_FILE paramsValues:@{kAccount: userInfo.account} paramsFileName:UPLOAD_FILE_PARAM_NAME paramsFileData:fileInfoArr completeHandler:^(id result, NSString *errorMessage) {
            
            [uploadOperation_ removeObserver:self forKeyPath:@"progress"];
            
            if (errorMessage) {
                [self.updateUserInfoQueue cancelAllOperations];
                completeHandler(nil,errorMessage);
            }else if(result){
                NSError *err;
                NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingMutableContainers error:&err];
                if (err) {
                    completeHandler(nil,NET_ERROR_MSG_FOR_RESPONSE_JSON_DATA);
                }else{
                    NSLog(@"文件上传结果：%@",dict);
                    // 检查errorCode
                    if ([dict[kErrorCode]intValue] == 0) {
                        //handler(dict[kinfo],nil);
                        
                        NSMutableString *fileIdsStr = [NSMutableString string];
                        NSArray *infoArr = dict[kinfo];
                        for (NSDictionary *fileDict in infoArr) {
                            [fileIdsStr appendString:fileDict[kFileId]];
                            [fileIdsStr appendString:SEPERATOR_FOR_FILE_IDS];
                        }
                        NSLog(@"fileIds:%@",fileIdsStr);
                        NSLog(@"头像更新地址：%@",NET_IF_DYNAMIC_PUBLISH);
                        
                        operation -> paramsDict_ = @{kAccount:userInfo.account,kPassword:userInfo.password,kBirtDate:(birthDate == nil ? @"" : birthDate),kGradUniv : gradUniv == nil ? @"" : gradUniv,kEduc : educ == nil ? @"" : educ, kSign : sign == nil ? @"" : sign, kPhon : phone == nil ? @"" : phone, kFileIds:fileIdsStr};
                    }else{
                        completeHandler(nil,dict[kErrorMessage]);
                    }
                }
            }
        }];
        
        [operation addDependency:uploadOperation_];
        // 添加观察者
        [uploadOperation_ addObserver:self forKeyPath:@"progress" options:NSKeyValueObservingOptionNew context:NULL];
        
        [self.updateUserInfoQueue addOperation:uploadOperation_];
    }
    [self.updateUserInfoQueue addOperation:operation];
}



// 获取用户密码
#warning 此方法废弃
/*- (void)queryUserInfoPass:(DataHandleComplete)completeHandler{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_PASS_DETA requestMethod:NET_REQUEST_GET paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
}*/

// 修改密码
- (void)updateUserInfoWithNewPass:(NSString *)newPass
                  completeHandler:(DataHandleComplete)completeHandler{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_PASS_UPDA requestMethod:NET_REQUEST_POST paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password,kNewPass:newPass} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
}

// 修改邮箱
- (void)updateUserInfoWithMail:(NSString *)mail completeHandler:(DataHandleComplete)completeHandler{
    BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
    IMB_NetWorkJsonRespOperation *operation = [[IMB_NetWorkJsonRespOperation alloc]initWithUrlStr:NET_IF_USER_INFO_MAIL_UPDA requestMethod:NET_REQUEST_POST paramsValues:@{kAccount:userInfo.account,kPassword:userInfo.password,kMail:mail} completeHandler:^(id result, NSString *errorMessage) {
        if (result) {
            if ([result[kErrorCode]intValue] == 0) {
                completeHandler(result[kinfo],errorMessage);
            }else{
                completeHandler(nil,result[kErrorMessage]);
            }
        }else{
            completeHandler(nil,errorMessage);
        }
    }];
    [[[NSOperationQueue alloc]init] addOperation:operation];
}


#pragma mark - Property method

// 更新用户信息
- (NSOperationQueue*)updateUserInfoQueue{
    if (!_updateUserInfoQueue) {
        _updateUserInfoQueue = [[NSOperationQueue alloc]init];
    }
    return _updateUserInfoQueue;
}

// 获取家长的首页信息
- (NSOperationQueue*)queryParentHomeInfoQueue{
    if (!_queryParentHomeInfoQueue) {
        _queryParentHomeInfoQueue = [[NSOperationQueue alloc]init];
    }
    return _queryParentHomeInfoQueue;
}

// 获取教师首页信息
- (NSOperationQueue*)queryTeacherHomeInfoQueue{
    if (!_queryTeacherHomeInfoQueue) {
        _queryTeacherHomeInfoQueue = [[NSOperationQueue alloc]init];
    }
    return _queryTeacherHomeInfoQueue;
}

- (NSOperationQueue*)queryEvalListQueue{
    if (!_queryEvalListQueue) {
        _queryEvalListQueue = [[NSOperationQueue alloc]init];
    }
    return _queryEvalListQueue;
}

#pragma mark - Life Cycle method

- (void)dealloc{
    NSLog(@"BN_MyInfoHelper dealloc .......");
    if (uploadOperation_) {
        [uploadOperation_ removeObserver:self forKeyPath:@"progress"];
    }
}

- (id)init{
    
    if(self = [super init]){
        evalArr_ = [NSMutableArray array];
        parentHomeInfoArr_ = [NSMutableArray array];
    }
    return self;
}

// 观察者回调
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
    if ([keyPath isEqualToString:@"progress"]) {
        IMB_NetWorkAccessOperationWithFilesUpload *operation = object;
        uploadProcessingHandler_(operation.progress);
    }
}


@end
